<?php
 
error_reporting(1);
 
$target = dirname(__FILE__) ; // 生产环境web目录
 
 
$file=$target."/hook/hook_log";
  
$file=$file.".txt";
 
$token = '111';
$wwwUser = 'www';
$wwwGroup = 'www';
 
$json  =$GLOBALS['HTTP_RAW_POST_DATA'];

     $data = json_decode($json,true);
 
     file_put_contents($file,$json.PHP_EOL,FILE_APPEND);

if (empty($data['password']) || $data['password'] !== $token) {
    // file_put_contents($file1,time()."密码错误");
    exit('error request');
}
 
 
 
// $cmds = array(
//     "cd $target && git pull",
//     "chown -R {$wwwUser}:{$wwwGroup} $target/",
// );
 
// foreach ($cmds as $cmd) {
//     shell_exec($cmd);
// }
 
// 感谢@墨迹凡指正，可以直接用www用户拉取代码而不用每次拉取后再修改用户组
 
$cmd = "cd {$target} && git reset --hard && git pull origin master   ";
 
$info=shell_exec($cmd);

 



